<?php get_header(); ?>

<?php
global $authordata;
$aOptions         = SofaSuppaStore::initOptions( false );
$disable_comments = $aOptions[ 'disable_comments' ];
$trim_summary     = ( strlen( $aOptions[ 'trim_summary' ] ) > 0 ) ? stripslashes( $aOptions[ 'trim_summary' ] ) : 45;
?>

<!-- main content start -->

<div class="grid_8">

	<!-- wordpress loop start -->

	<?php if( have_posts() ) : while( have_posts() ) : the_post(); ?>
    
    <div id="post-<?php the_ID(); ?>" class="castshadow grid_8 clearfix alpha omega">

    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    
    <span class="sidenewsinfo small clearfix">
    <?php the_time( get_option( 'date_format' ) ); ?> 
    &bull; 
    <?php echo sprintf( __( 'Posted by <a href="%s">%s</a> in', 'sofa_suppastore' ), get_author_posts_url( $authordata->ID, $authordata->user_nicename ), get_the_author() ); ?> <?php the_category( ', ' ); ?>
    &bull; 
    <?php the_tags(); ?>
    <?php 
	if( $disable_comments == 'no' ) {
		echo ' &bull; ';
		comments_popup_link( '0 ' . __( "comments", "sofa_suppastore" ), '1 ' . __( "comment", "sofa_suppastore" ), '% ' . __( "comments", "sofa_suppastore" ) ); 
	}
	?>
    </span>
    
    <span class="underline clearfix">&nbsp;</span>
    
    <?php
	$thumb_data = '';
	$c_post_id = intval( get_the_ID() );
	$c_post_perma = get_permalink( $c_post_id );
	/* extract image - if any */
	$attImagez = array();
	$attImagez =& get_children( 'post_type=attachment&post_mime_type=image&orderby=menu_order&order=ASC&post_parent=' . $c_post_id );
	$arrIM = array_keys( $attImagez );
	if( $arrIM[ 0 ] ) {
		$targ_img = wp_get_attachment_image_src( $arrIM[ 0 ], 'thumbnail' );
		$thumb_data .= '<a href="' . $c_post_perma . '">';
		$thumb_data .= '<img src="' . $targ_img[ 0 ] . '" class="size-thumbnail alignleft" alt="" />';
		$thumb_data .= '</a>';
	}
	
	echo '<p>' . $thumb_data . trim_the_content( get_the_excerpt(), __( "...READ MORE", "sofa_suppastore" ), $c_post_perma, (int)$trim_summary ) . '</p>';
    ?>
    
    </div>

	<?php endwhile; ?>
    
    <!-- wordpress loop end -->
    
    <!-- pagination start -->

	<?php
	get_template_part( 'wp-pagenavi' );
	if( function_exists( 'wp_page_numbers' ) ) {
		wp_page_numbers();
	}
	elseif( function_exists( 'wp_pagenavi' ) ) {
		wp_pagenavi();
	} else {
		global $wp_query;
		$total_pages = $wp_query->max_num_pages;
		if ( $total_pages > 1 ) {
			echo '<div id="pagination" class="wp-pagenavi grid_8 alpha omega"><span class="nava">';
				posts_nav_link( ' ', __( '&laquo; Previous page', 'sofa_suppastore' ), __( 'Next page &raquo;', 'sofa_suppastore' ) );
			echo '</span></div>';
		}
	}
    ?>
    
    <!-- pagination end -->
    
	<script type="text/javascript">
    
    jQuery( document ).ready( function() {
        // remove captions
		jQuery( '.wp-caption' ).each( function() {
			jQuery( 'p.wp-caption-text', this ).replaceWith( '' );
			var castshadow_content = jQuery( this ).contents();
			jQuery( this ).replaceWith( castshadow_content );
		} );
    } );
        
    </script>
    
    <?php else : ?>
    
    <!-- no content start -->

	<div class="grid_8 clearfix">
    
        <h1><?php _e( "Nothing found!", "sofa_suppastore" ); ?></h1>
        <p><?php _e( "Sorry but no posts found. Take your time, there's gonna be soon to see something listed here.", "sofa_suppastore" ); ?></p>
    
    </div>
    
    <!-- no content end -->

	<?php endif; ?>
    
</div>

<!-- main content end -->

<!-- include sidebar start -->

    <?php get_template_part( 'sidebar_category' ); ?>
    
<!-- include sidebar end -->

<?php get_footer(); ?>